import {
  CART_INFO, CART_SAVE, CART_UPDATE, CART_DELETE, CART_SELECT_ALL
} from '@constants/cart'
import {
  API_CART_INFO, API_CART_SAVE, API_CART_UPDATE, API_CART_DELETE, API_CART_SELECT_ALL
} from '@constants/api'
import { createAction } from '@utils/redux'

/**
 * 购物车信息
 * @param {*} payload
 */
export const dispatchCart = payload => createAction({
  url: API_CART_INFO,
  type: CART_INFO,
  fetchOptions: {
    autoLogin: false
  },
  payload
})

/**
 * 添加商品到购物车
 * @param {*} payload
 */
export const dispatchCartSave = payload => createAction({
  url: API_CART_SAVE,
  method: 'POST',
  type: CART_SAVE,
  payload
})


/**
 * 修改购物车商品
 * @param {*} payload
 */
export const dispatchCartUpdate = payload => createAction({
  url: API_CART_UPDATE,
  method: 'POST',
  type: CART_UPDATE,
  payload
})


/**
 * 删除购物车商品
 * @param {*} payload
 */
export const dispatchCartDelete = payload => createAction({
  url: API_CART_DELETE,
  type: CART_DELETE,
  payload
})

/**
 * 全选
 * @param {*} payload
 */
export const dispatchCartSelectAll = payload => createAction({
  url: API_CART_SELECT_ALL,
  type: CART_SELECT_ALL,
  payload
})
